#include "InfoScreen.h"
#include <iostream>
InfoScreen::InfoScreen(sf::RenderWindow* window, StateMachine* state_machine, sf::Text message) :
						GameState(state_machine), _window(window), _message(message)

{
	//_victory_message.setString(L"Victory !!!");
	_return_menu.setString(L"Menu");
	float x=window->getSize().x/2;
	_message.setColor(sf::Color::Red);
	_message.setPosition(x, window->getSize().y /3);
	_return_menu.setPosition(x, window->getSize().y * 2/3);

	if (!_font.loadFromFile("police.ttf"))
		std::cerr<<"Error : police not found"<<std::endl;
	else
	{
		_message.setFont(_font);
		_return_menu.setFont(_font);
	}

	_message.setOrigin(_message.getLocalBounds().width/2,0);
	_return_menu.setOrigin(_return_menu.getLocalBounds().width/2,0);

}

InfoScreen::~InfoScreen(){}

void InfoScreen::init(){
}

void InfoScreen::handleEvents()
{
	sf::Event event;
    while(_window->pollEvent(event))
    {
        if(event.type == sf::Event::Closed)
            _window->close();
    }

	if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
	{
		sf::Vector2i mouse_pos = sf::Mouse::getPosition(*_window);
		if( _return_menu.getGlobalBounds().contains(mouse_pos.x,mouse_pos.y))
		{
			_state_machine->changeState(state::menu);
		}
	}
}

void InfoScreen::update()
{
	_window->clear();
	draw();
	handleEvents();
}

void InfoScreen::draw(){
	_window->draw(_message);
	_window->draw(_return_menu);
	_window->setView(_window->getDefaultView());
}

void InfoScreen::exit(){}